package yawning.mew.character;

import java.util.Properties;

import yawning.mew.MewProperty;
import yawning.mew.PropertiesBase;

public class PropertiesToonBuilder {
    public static class Property {
        public static final MewProperty LEVEL = new MewProperty("Level", 0);
        public static final MewProperty CLASS = new MewProperty("Class", "Druid");
        public static final MewProperty RACE = new MewProperty("Race", "Night Elf");
        public static final MewProperty TALENTSPEC = new MewProperty("TalentSpec", "Druid.Feral");

        public static final MewProperty STRENGTH = new MewProperty("Strength", 0);
        public static final MewProperty AGILITY = new MewProperty("Agility", 0);
        public static final MewProperty STAMINA = new MewProperty("Stamina", 0);
        public static final MewProperty INTELLECT = new MewProperty("Intellect", 0);
        public static final MewProperty SPIRIT = new MewProperty("Spirit", 0);
        public static final MewProperty ARMOR = new MewProperty("Armor", 0);
        public static final MewProperty BONUSARMOR = new MewProperty("BonusArmor", 0);

        public static final MewProperty ATTACKPOWER = new MewProperty("AttackPower", 0);
        public static final MewProperty HASTERATING = new MewProperty("HasteRating", 0);
        public static final MewProperty CRITRATING = new MewProperty("CritRating", 0);
        public static final MewProperty HITRATING = new MewProperty("HitRating", 0);
        public static final MewProperty EXPERTISERATING = new MewProperty("ExpertiseRating", 0);
        public static final MewProperty MASTERYRATING = new MewProperty("MasteryRating", 0);
        public static final MewProperty DODGERATING = new MewProperty("DodgeRating", 0);
        public static final MewProperty PARRYRATING = new MewProperty("ParryRating", 0);
        public static final MewProperty RESILIENCERATING = new MewProperty("ResilienceRating", 0);

        public static final MewProperty WEAPONTOP = new MewProperty("WeaponTop", 0);
        public static final MewProperty WEAPONBOTTOM = new MewProperty("WeaponBottom", 0);
        public static final MewProperty WEAPONSPEED = new MewProperty("WeaponSpeed", 0);

        public static final MewProperty TIER_10_2PC = new MewProperty("Tier_10_2pc", false);
        public static final MewProperty TIER_10_4PC = new MewProperty("Tier_10_4pc", false);

        public static final MewProperty TIER_11_2PC = new MewProperty("Tier_11_2pc", false);
        public static final MewProperty TIER_11_4PC = new MewProperty("Tier_11_4pc", false);

        public static final MewProperty TIER_12_2PC = new MewProperty("Tier_12_2pc", false);
        public static final MewProperty TIER_12_4PC = new MewProperty("Tier_12_4pc", false);

        public static final MewProperty TIER_13_2PC = new MewProperty("Tier_13_2pc", false);
        public static final MewProperty TIER_13_4PC = new MewProperty("Tier_13_4pc", false);

        public static final MewProperty PVP_GLOVES = new MewProperty("PvP_gloves", false);

        public static final MewProperty ARMORSPEC = new MewProperty("ArmorSpec", true);
        public static final MewProperty WEAPONRACIAL = new MewProperty("WeaponRacial", false);
        public static final MewProperty METAGEM = new MewProperty("MetaGem", "none");
    }

    private PropertiesBase mProperties;

    public PropertiesToonBuilder setProperties(Properties props) {
    	mProperties = new PropertiesBase(props);
    	return this;
    }

    public PropertiesToonBuilder setConfig(PropertiesBase config) {
    	mProperties = config;
    	return this;
    }

    public Toon build() {
    	Toon c = new Toon();
    	c.level = mProperties.getInt(Property.LEVEL);
    	c.mRace = Race.get(mProperties.getString(Property.RACE));
    	c.strength = mProperties.getInt(Property.STRENGTH);
    	c.agility = mProperties.getInt(Property.AGILITY);
    	c.stamina = mProperties.getInt(Property.STAMINA);
    	c.intellect = mProperties.getInt(Property.INTELLECT);
    	c.spirit = mProperties.getInt(Property.SPIRIT);
    	c.armor = mProperties.getInt(Property.ARMOR);
    	c.bonusArmor = mProperties.getInt(Property.BONUSARMOR);
    	c.attackPower = mProperties.getInt(Property.ATTACKPOWER);
    	c.mDodgeRating = mProperties.getInt(Property.DODGERATING);
    	c.mParryRating = mProperties.getInt(Property.PARRYRATING);
    	c.hasteRating = mProperties.getInt(Property.HASTERATING);
    	c.critRating = mProperties.getInt(Property.CRITRATING);
    	c.hitRating = mProperties.getInt(Property.HITRATING);
    	c.expertiseRating = mProperties.getInt(Property.EXPERTISERATING);
    	c.masteryRating = mProperties.getInt(Property.MASTERYRATING);
    	c.mResilienceRating = mProperties.getInt(Property.RESILIENCERATING);
    	c.weaponTop = mProperties.getInt(Property.WEAPONTOP);
    	c.weaponBottom = mProperties.getInt(Property.WEAPONBOTTOM);
    	c.weaponSpeed = mProperties.getInt(Property.WEAPONSPEED);
    	c.tier_10_2pc = mProperties.getBool(Property.TIER_10_2PC);
    	c.tier_10_4pc = mProperties.getBool(Property.TIER_10_4PC);
    	c.tier_11_2pc = mProperties.getBool(Property.TIER_11_2PC);
    	c.tier_11_4pc = mProperties.getBool(Property.TIER_11_4PC);
    	c.tier_12_2pc = mProperties.getBool(Property.TIER_12_2PC);
    	c.tier_12_4pc = mProperties.getBool(Property.TIER_12_4PC);
    	c.tier_13_2pc = mProperties.getBool(Property.TIER_13_2PC);
    	c.tier_13_4pc = mProperties.getBool(Property.TIER_13_4PC);
    	c.pvp_gloves = mProperties.getBool(Property.PVP_GLOVES);
    	c.isArmorSpec = mProperties.getBool(Property.ARMORSPEC);
    	c.isWeaponRacial = mProperties.getBool(Property.WEAPONRACIAL);

    	String metagem = mProperties.getString(Property.METAGEM);
    	for (MetaGem gem : MetaGem.values()) {
    		if (metagem.equals(gem.getKey())) {
    			c.mMetaGem = gem;
    			break;
    		}
    	}

    	c.mClass = Clazz.get(mProperties.getString(Property.CLASS));

    	Properties p = mProperties.getProperties();
    	for (Glyph g : c.mClass.getGlyphs()) {
    		String value = p.getProperty(g.toString());
    		if (value != null && value.equals("true")) c.mGlyphs.add(g);
    	}
    	for (Talent t : c.mClass.getTalents()) {
    		int n = Integer.parseInt(p.getProperty("Talent." + t.toString(), "0"));
    		if (n > 0) c.mTalents[t.getId()] = (byte)n;
    	}

    	c.mTalentSpec = TalentTree.get(c.mClass, mProperties.getString(Property.TALENTSPEC));

    	return c;
    }
}
